/**
 * FileName: TsfController
 * Author:   powersi
 * Date:     2021/1/1 11:49
 * Description: 1
 */
package com.zm.demo.httpclient;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Description: 1
 * Author:      powersi
 * Date:        2021/1/1 11:49
 */
@RestController
@RequestMapping
@SpringBootApplication
@Api("监控项管理")
public class ManagementController {

    @Autowired
    TsfQueryExcutor tsfQueryExcutor;

   @ApiOperation(value = "监控项添加", notes = "增加")
    @RequestMapping(value = "addItem", method = RequestMethod.GET)
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "type", required = true, paramType="query", dataType = "String", defaultValue = "", value = "类型：tsf, tdsql, email"),
                    @ApiImplicitParam(name = "key", required = true, paramType="query", dataType = "String", defaultValue = "", value = "两定接口路径如：/fsi/api/fsiPsnInfoService/queryPsnInfo\ntdsql实例信息如：/tdsqlzk/group_1600835079_1576"),
                    @ApiImplicitParam(name = "desc", required = true, paramType="query", dataType = "String", defaultValue = "",value = "描述信息")}
    )
    public String addItem(String type, String key, String desc) throws Exception{
        if (Objects.equals(type, Item.tsf.name())){
            TsfQueryExcutor.mapParam.put(key, desc);
        }
        if (Objects.equals(type, Item.tdsql.name())){
            TsfQueryExcutor.tdsqlInstance.put(key,desc);
        }
        if (Objects.equals(type, Item.email.name())){
            SendMailService.emailMap.put(key,desc);
        }
        return "ok";
    }

   @ApiOperation(value = "监控项删除", notes = "")
    @RequestMapping(value = "delItem", method = RequestMethod.GET)
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "type", required = true, paramType="query", dataType = "String", defaultValue = "tsf",value = "类型：tsf, tdsql, email"),
                    @ApiImplicitParam(name = "key", required = true, paramType="query", dataType = "String", defaultValue = "")}
    )
    public String delItem(String type, String key) throws Exception{
        if (Objects.equals(type, Item.tsf.name())){
            TsfQueryExcutor.mapParam.remove(key);
        }
        if (Objects.equals(type, Item.tdsql.name())){
            TsfQueryExcutor.tdsqlInstance.remove(key);
        }
       if (Objects.equals(type, Item.email.name())){
           SendMailService.emailMap.remove(key);
       }
       return "ok";
    }

   @ApiOperation(value = "监控项查询", notes = "")
    @RequestMapping(value = "getItems", method = RequestMethod.GET)
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "type", required = true, paramType="query", dataType = "String", defaultValue = "tsf",value = "类型：tsf, tdsql, email")}
    )
    public Map<String,String> getItems(String type) throws Exception{
        if (Objects.equals(type, Item.tsf.name())){
            return TsfQueryExcutor.mapParam;
        }
        if (Objects.equals(type, Item.tdsql.name())){
            return TsfQueryExcutor.tdsqlInstance;
        }
       if (Objects.equals(type, Item.email.name())){
           return SendMailService.emailMap;
       }
       return null;
    }

    enum Item{
       tdsql,
        tsf,
        email
    }
}
